package org.springmvc.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springmvc.model.BaseEntity;
import org.springmvc.pagination.PageRequest;

/**
 * 基础Controller
 * <pre>
 * 定义基本的模块操作接口
 * </pre>
 * @author 唐家林
 * @time 2015年5月22日
 */
public abstract class AbstractBaseController<E extends BaseEntity> {
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	/**
	 * 模块主视图
	 * @param request HttpServletRequest
	 * @param response HttpServletResponse
	 * @return 返回该模块的主视图
	 */
	public abstract String view(HttpServletRequest request, HttpServletResponse response);

	/**
	 * 获取单个实体详细信息
	 * @param id 实体主键
	 * @param request HttpServletRequest
	 * @param response HttpServletResponse
	 * @param jsonCallback 用于支持跨域JSONP请求的回调函数
	 * @return
	 */
	public abstract String get(Integer id, HttpServletRequest request, HttpServletResponse response, String jsonCallback);

	/**
	 * 列表查询
	 * @param request HttpServletRequest
	 * @param response HttpServletResponse
	 * @param jsonCallback 用于支持跨域JSONP请求的回调函数
	 * @return 返回List的查询结果集
	 */
	public abstract String list(HttpServletRequest request, HttpServletResponse response, String jsonCallback);
	
	/**
	 * 分页查询
	 * @param pageable 分页参数
	 * @param request HttpServletRequest
	 * @param response HttpServletResponse
	 * @param jsonCallback 用于支持跨域JSONP请求的回调函数
	 * @return 返回带有分页数据的查询结果
	 */
	public abstract String paginate(PageRequest pageable, HttpServletRequest request, HttpServletResponse response, String jsonCallback);

	/**
	 * 保存实体信息
	 * @param entity 保存的实体
	 * @param request HttpServletRequest
	 * @param response HttpServletResponse
	 * @param jsonCallback 用于支持跨域JSONP请求的回调函数
	 * @return 返回成功操作结果
	 */
	public abstract String update(E entity, HttpServletRequest request, HttpServletResponse response, String jsonCallback);

	/**
	 * 根据实体主键删除实体
	 * @param ids 删除的实体主键
	 * @param request HttpServletRequest
	 * @param response HttpServletResponse
	 * @param jsonCallback 用于支持跨域JSONP请求的回调函数
	 * @return 返回成功操作结果
	 */
	public abstract String delete(Integer[] ids, HttpServletRequest request, HttpServletResponse response, String jsonCallback);
}
